
Partial Class ViewE
    Inherits System.Web.UI.Page

    Private Const Q As String = Chr(34)

    Private moServer As SQLAutoDocLib.Server = Nothing
    Private moDatabase As SQLAutoDocLib.Database = Nothing

    Dim msSID As String
    Dim msDID As String
    Dim mlSort As SQLAutoDocLib.View_Factory.SORT

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            msSID = Request.QueryString("S")
            msDID = Request.QueryString("D")
            Dim sSort As String = Request.QueryString("SORT")

            If IsNumeric(sSort) Then
                mlSort = sSort
            Else
                mlSort = SQLAutoDocLib.SProc_Factory.SORT.DATE_DESC
            End If

            hidSID.Value = msSID
            hidDID.Value = msDID
            hidSort.Value = mlSort

            ARefresh.HRef = "SQViewE.aspx?S=" & msSID & "&D=" & msDID & "&SORT=" & mlSort
        Else
            msSID = hidSID.Value
            msDID = hidDID.Value
            mlSort = hidSort.Value
        End If

        moServer = New SQLAutoDocLib.Server(msSID)
        moServer.Load()

        moDatabase = New SQLAutoDocLib.Database(msDID)
        moDatabase.Load()
    End Sub

    Protected Sub ShowViewList()
        Dim sURL As String = "SQViewE.aspx?S=" & msSID & "&D=" & msDID & "&SORT="

        Dim sHTM As New StringBuilder

        sHTM.Append("<table class=" & Q & "wmObjectList_T" & Q & ">")

        sHTM.Append("<tr class=" & Q & "wmObjectList_TH" & Q & " style=" & Q & "height: 39px; background-color: #C3C4C1; border-bottom: solid 1px black;" & Q & ">")

        sHTM.Append("<td class=" & Q & "wmObjectList_ZC" & Q & ">")
        sHTM.Append("&nbsp;")
        sHTM.Append("</td>")

        sHTM.Append("<td class=" & Q & "wmObjectList_ZM" & Q & ">")
        sHTM.Append("<span style=" & Q & "white-space: nowrap;" & Q & ">")

        If mlSort <> SQLAutoDocLib.SProc_Factory.SORT.DATE_ASC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.DATE_ASC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Date" & Q & _
                         " title=" & Q & "Ascending Order by Date" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Date" & Q & _
                         " title=" & Q & "Ascending Order by Date" & Q & _
                         "/>")
        End If

        If mlSort <> SQLAutoDocLib.SProc_Factory.SORT.DATE_DESC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.DATE_DESC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Date" & Q & _
                         " title=" & Q & "Descending Order by Date" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Date" & Q & _
                         " title=" & Q & "Descending Order by Date" & Q & _
                         "/>")
        End If

        sHTM.Append("Modified")
        sHTM.Append("</span>")
        sHTM.Append("</td>")

        sHTM.Append("<td class=" & Q & "wmObjectList_ZR" & Q & ">")
        sHTM.Append("<span style=" & Q & "white-space: nowrap;" & Q & ">")
        If mlSort <> SQLAutoDocLib.SProc_Factory.SORT.VER_ASC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.VER_ASC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Revision" & Q & _
                         " title=" & Q & "Ascending Order by Revision" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Revision" & Q & _
                         " title=" & Q & "Ascending Order by Revision" & Q & _
                         "/>")
        End If

        If mlSort <> SQLAutoDocLib.SProc_Factory.SORT.VER_DESC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.VER_DESC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Revision" & Q & _
                         " title=" & Q & "Descending Order by Revision" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Revision" & Q & _
                         " title=" & Q & "Descending Order by Revision" & Q & _
                         "/>")
        End If
        sHTM.Append("Rev")
        sHTM.Append("</span>")
        sHTM.Append("</td>")

        sHTM.Append("<td class=" & Q & "wmObjectList_ZN" & Q & ">")
        sHTM.Append("<span style=" & Q & "white-space: nowrap;" & Q & ">")
        If mlSort <> SQLAutoDocLib.SProc_Factory.SORT.NAME_ASC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.NAME_ASC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Name" & Q & _
                         " title=" & Q & "Ascending Order by Name" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Name" & Q & _
                         " title=" & Q & "Ascending Order by Name" & Q & _
                         "/>")
        End If

        If mlSort <> SQLAutoDocLib.SProc_Factory.SORT.NAME_DESC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.NAME_DESC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Name" & Q & _
                         " title=" & Q & "Descending Order by Name" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Name" & Q & _
                         " title=" & Q & "Descending Order by Name" & Q & _
                         "/>")
        End If
        sHTM.Append("Name")
        sHTM.Append("</span>")
        sHTM.Append("</td>")

        sHTM.Append("</tr>")

        Dim oList As New ArrayList

        Dim bAlternatingRow As Boolean = False

        Dim oFactory As New SQLAutoDocLib.View_Factory
        For Each oView As SQLAutoDocLib.View In oFactory.GetAllViewsForDatabase(moDatabase.ID)
            If bAlternatingRow = False Then
                sHTM.Append("<tr class=" & Q & "wmObjectList_T" & Q & ">")
            Else
                sHTM.Append("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
            End If

            sHTM.Append("<td>")
            sHTM.Append("<a href=" & Q & "SQViewD.aspx?S=" & moServer.ID & "&D=" & moDatabase.ID & "&O=" & oView.ID & Q & ">")
            sHTM.Append("<img src=" & Q & "images/help.gif" & Q & " border=0/>")
            sHTM.Append("</a>")

            sHTM.Append("</td>")

            sHTM.Append("<td>")
            sHTM.Append(oView.LastModified)
            sHTM.Append("</td>")

            sHTM.Append("<td>")
            sHTM.Append(oView.RevID)
            sHTM.Append("</td>")

            sHTM.Append("<td>")
            sHTM.Append(oView.Name)
            sHTM.Append("</td>")

            sHTM.Append("</tr>")

            If oView.Desc.Length > 0 Then
                If bAlternatingRow = False Then
                    sHTM.Append("<tr class=" & Q & "wmObjectList_T" & Q & ">")
                Else
                    sHTM.Append("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
                End If

                sHTM.Append("<td>")
                sHTM.Append("&nbsp;")
                sHTM.Append("</td>")

                sHTM.Append("<td>")
                sHTM.Append("&nbsp;")
                sHTM.Append("</td>")

                sHTM.Append("<td colspan=" & Q & "2" & Q & ">")
                sHTM.Append(oView.Desc)
                sHTM.Append("</td>")

                sHTM.Append("</tr>")
            End If

            bAlternatingRow = Not bAlternatingRow
        Next

        sHTM.Append("</table>")

        HttpContext.Current.Response.Write(sHTM.ToString)
    End Sub

    Protected Function FormLabel() As String
        Dim oFactory As New SQLAutoDocLib.ScanHistory_Factory
        Dim sCurrentScan As String = ""
        Dim sLastScan As String = ""
        oFactory.GetTimeOfLastScan(moDatabase.ID, SQLAutoDocLib.ScanSchedule.Type.SchemaScan, "SQLAutoDocLib.View", sCurrentScan, sLastScan)

        Dim sValue As String = "View View List for " & moDatabase.Name & " last scan completed " & sLastScan

        If sCurrentScan > "" Then
            sValue = " scan in progress started " & sCurrentScan
        End If

        Return sValue
    End Function

    Protected Function ScanMode() As String
        Return "Views"
    End Function

    Protected Function EditMode() As String
        Return "View"
    End Function

    Protected Function ServerID() As String
        Return moServer.ID
    End Function

    Protected Function DatabaseID() As String
        Return moDatabase.ID
    End Function
End Class
